package com.slkj.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.slkj.mapper.DocsReplyLogMapper;
import com.slkj.pojo.DocsReplyLog;

import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Service
public class DocsReplyLogService {

    @Resource
    private DocsReplyLogMapper replyLogMapper;

    //增：某个公文的  Log日志
    public void addDocsReplyLog(DocsReplyLog docsReplyLog){
        replyLogMapper.insertSelective(docsReplyLog);
    }

    //修改
    public void updateLog(DocsReplyLog docsReplyLog){
        replyLogMapper.updateByPrimaryKeySelective(docsReplyLog);
    }


    //根据UUID显示。所有的收件人。详细信息
    public List<DocsReplyLog> findByDocUUid(String docUuid){
        Example example = new Example(DocsReplyLog.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("docUuid",docUuid);
      return   replyLogMapper.selectByExample(example);

    }

    //多条件查询
    public Page<DocsReplyLog> findDocLogList(Map<String,Object> searchMap, Integer page, Integer pageSize){
        PageHelper.startPage(page,pageSize);
        Example example = createExample(searchMap);
        return  (Page<DocsReplyLog>)replyLogMapper.selectByExample(example);
    }

    private Example createExample(Map<String, Object> searchMap) {
        Example example = new Example(DocsReplyLog.class);
        Example.Criteria criteria = example.createCriteria();
        if (searchMap != null) {
            //文件唯一标识
            if (searchMap.get("docUuid") != null) {
                criteria.andEqualTo("docUuid", searchMap.get("docUuid"));
            }
            //收件人
            if (searchMap.get("receivePeople") != null) {
                criteria.andEqualTo("receivePeople", searchMap.get("receivePeople"));
            }
            //收件人状态
            if (searchMap.get("receivePeopleStatus") != null) {
                criteria.andEqualTo("receivePeopleStatus", searchMap.get("receivePeopleStatus"));
            }
       /*
            if (searchMap.get("replyTime") != null) {
                criteria.andEqualTo("replyTime", searchMap.get("replyTime"));
            }*/
        }
        return example;
    }

    //添加收藏 根据UUID和名字
    public void collectLogByUUIDAndName(String uuid, String name){
        replyLogMapper.collectLogByUUIDAndName(uuid,name);}

    //根据收藏和名字   显示UUID
    public  List<String>  findUUIDByCollectAndName(String name){
         return    replyLogMapper.findUUIDByCollectAndName(name);
    }

    //已读   根据UUID和名字
    public  void readByUUIDAndName(String uuid, String name){
        replyLogMapper.readByUUIDAndName(uuid,name);
    }

    //已读未读的比例
    public  double readPoint( String uuid){
      return   replyLogMapper.readPoint(uuid);
    }
    //根据名字查UUID
    public Set<String> findUuidByName(String name){
        return  replyLogMapper.uuidByName(name);
    }
}
